<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn1">测试</button>
    <button class="btn">测试</button>
    <button a="1">测试</button>
    <button b="2">测试</button>
    <button b="3">测试</button>
    <button b="4">测试</button>
    <button>测试</button>
    <button>测试</button>
    <button>测试</button>
    <button>测试</button>
    <button>测试</button>
    <script>
        // document.querySelector("button").onclick = () => {
        //     alert('测试')
        // }
        // document.querySelectorAll("button").forEach(item => {
        //     // item.onclick = () => {
        //     //     alert('测试')
        //     // }
        //     item.addEventListener('click', () => {
        //         alert('测试')
        //     })
        // })
        document.querySelector('#btn1').onclick = () => {
            alert('测试')
        }
        document.querySelector('.btn').onclick = () => {
            alert('测试')
        }
        document.querySelector('button[b="2"]').onclick = () => {
            alert('测试11111')
        }
    </script>
</body>

</html>